package com.nowcoder.Offer.FlowWindow;

import org.junit.Test;

import java.util.ArrayList;
import java.util.PriorityQueue;

/**
 * 滑动窗口的最大值
 */
public class Offer_01 {
    public ArrayList<Integer> maxInWindows(int [] num, int size){
        ArrayList<Integer> ans = new ArrayList<>();
        if(size == 0) return  ans;
        int index = 0;
        PriorityQueue<Integer> queue = new PriorityQueue<>((a,b) -> b-a);

        for(int i = 0; i<size;i++){
            queue.offer(num[i]);
        }

        for(int i = size; i<num.length; i++){
            ans.add(queue.peek());
            queue.remove(num[i-size]);
            queue.offer(num[i]);
        }
        ans.add(queue.peek());
        return ans;
    }

    @Test
    public void test(){
        int[] arr = {2,3,4,2,6,2,5,1};
        for(Integer i : maxInWindows(arr,3))
            System.out.print(i+" ");
    }
}
